/*
 * Project Name spring-boot-tools
 * File Name CreateTablesImportSelector
 * Package Name com.huxiaosu.tools.mybatis.selector
 * Create Time 2024/7/9
 * Create by name：liujie
 */
package com.huxiaosu.tools.autocreate.selector;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.annotation.DbType;
import com.huxiaosu.tools.autocreate.AutoCreateAware;
import com.huxiaosu.tools.autocreate.AutoCreatePool;
import com.huxiaosu.tools.autocreate.annotation.EnableCreateDataBases;
import com.huxiaosu.tools.autocreate.config.AutoCreateTableProperties;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * Description
 *
 * @author liujie
 * @date 2024/7/9 15:05
 */
public class CreateDataBasesImportSelector implements ImportSelector {
    @Override
    public String[] selectImports( AnnotationMetadata importingClassMetadata) {
        Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnableCreateDataBases.class.getName());
        if(CollUtil.isEmpty(annotationAttributes)){
            return new String[]{AutoCreateTableProperties.class.getName()};
        }
        DbType type = (DbType) annotationAttributes.get("value");
        AutoCreateAware createDatabaseDao = AutoCreatePool.getCreateDatabaseDao(type);
        String name = createDatabaseDao.getClass().getName();
        return new String[]{name, AutoCreateTableProperties.class.getName()};
    }



}